package com.itcrx.algorithm.recursion;

/**
 * @author NoobMaster69  * @date 2024/6/17 0017 星期一 19:00
 */
public class E05InsertionSort {

    public static void sort(int[] a){
        insertion(a,1);
    }
    private static void insertion(int[] a, int low) {
        if (low == a.length) {
            return;
        }

        int temp = a[low];
        int i = low - 1;    //已排序区域的指针
        while (i>=0 && a[i] > temp){   //没有找到插入位置
            a[i + 1] = a[i];    //空出插入位置
            i--;
        }

        //找到插入位置

        a[i+1] = temp;
        insertion(a, low + 1);
    }
}
